const UPPER_ATACK_PER_LEVEL = 10;
const UPPER_MAXHP_PER_LEVEL = 100;

    let mountedItems: Item[] = [];

   let packagedItems: Item[] = [];          

/**
 * 用户数据
 * MVC：Model
 */
class User extends EventDispatcher {
    
    public roleTexturea=new Image();          
    private x = 0;
    public attack=100;
    public hp=100;

    private y = 0;
    public sliverCoin=6666;
    view: renderer.DisplayObject;
   // roleTexture=new Image();     
   // roleTexture.rc = 'role.png';
    constructor() {
        super();

     /*  const roleTexture=new Image();
         
      roleTexture.src = 'role.png';


        const role = new renderer.Bitmap(0, 0, roleTexture);
        role.alpha = 0.4;
        this.view = role;*/
      //  this.view.scaleX = this.view.scaleY = 0.7;

    }
    public createUser() {
       const roleTexture=new Image();
         
       roleTexture.src = 'boy2.png';
       this. roleTexturea.src = 'boy2.png';


        const role = new renderer.Bitmap(0, 0, roleTexture);
      //  role.alpha = 0.4;
        this.view = role;
        this.view.scaleX = this.view.scaleY = 0.8;

      //  user = new User();
        user.level = 1;
        user.name = 'boge';
        //user.view=new renderer.Bitmap(0,0,d);


       
        missionManager.init();



        console.log(user.toString())
    }
    public createUsera() {

         const roleTexture=new Image();
           
         roleTexture.src = 'girl2.png';
         this. roleTexturea.src = 'girl2.png';

          const role = new renderer.Bitmap(0, 0, roleTexture);
         // role.alpha = 0.4;
          this.view = role;
          this.view.scaleX = this.view.scaleY = 0.8;
  
        //  user = new User();
          user.level = 1;
          user.name = 'boge';
          //user.view=new renderer.Bitmap(0,0,d);
  
  
         
          missionManager.init();
  
  
  
          console.log(user.toString())
      }
     
  
   


    update() {
        const targetX = this.x * TILE_SIZE;
        const targetY = this.y * TILE_SIZE;
       
        this.view.x = targetX;
        this.view.y = targetY;
       
    }

    goto(x: number, y: number) {
        this.x = x;
        this.y = y;
       
    }


    name: string = '';


    

   /* get maxHp() {
        return this.level * UPPER_MAXHP_PER_LEVEL;
    }
*/

    private _level = 1;
    get level() {
        return this._level;
    }

    set level(value: number) {
        this._level = value;
        this.dispatchEvent("userchange", "111");
    }

    pick(item: Item) {
        packagedItems.push(item);
        console.log(`捡起${item.toString()}`);
        // this.dispatchEvent("userchange", '111');
    }

    setAttack(){
        console.log(666666666666);
        for(let item of mountedItems){
            
            if(item){
                 user.attack=user.attack+item.attack
                 this.dispatchEvent("userchange","111");
                 
            }else{
                return ;
            }
           
        }
        
    }
    
    



    // get attacka() {
    //     let itemAttack = 0;
    //     for (let item of mountedItems) {
    //         itemAttack += item.attack
    //     }
    //     return this.attacka;
    // }

    toString() {
        return `[User: level:${this.level} , attack:${this.attack} , ${mountedItems.map((item) => item.toString())}]`
    }
}









